﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using CLEXA.AdminClient.Cache;
using CLEXA.AdminClient.Services;
using CLEXA.AdminClient.ViewModel;
using CLEXA.ClientTools.Collections;
using CLEXA.DataContracts;
using CLEXA.ServiceContracts;

namespace CLEXA.AdminClient
{
    internal sealed class Facade : IFacade
    {
        private readonly IUserCache userCache;
        private readonly IWindowHelper windowHelper;

        public IReadOnlyObservableDictionary<int, UserData> Users
        {
            get { return userCache.Users; }
        }

        public Facade(IUserCache userCache, IWindowHelper windowHelper)
        {
            this.userCache = userCache;
            this.windowHelper = windowHelper;
        }

        public void UserCreate(string username, string password, bool isActive)
        {
            userCache.CreateUser(username, password, isActive);
        }

        public void UserUpdate(UserData user)
        {
            userCache.UpdateUser(user);
        }

        public void UserDelete(int userId)
        {
            userCache.DeleteUser(userId);
        }

        public void UserChangePassword(int userId, string password)
        {
            userCache.ChangeUserPassword(userId, password);
        }

        public void ShowUserChangePasswordDialog(int userId)
        {
            windowHelper.ShowUserChangePassword(this, userId);
        }

        public void ShowUserCreateDialog()
        {
            windowHelper.ShowCreateUser(this);
        }

        public void ShowUserEditDialog(int userId)
        {
            windowHelper.ShowUpdateUser(this, userId);
        }

        public void ShowErrorDialog(string message, Exception innerException)
        {
            windowHelper.ShowError(message, innerException);
        }

        public bool ShowYesOrNoDialog(string question)
        {
            return windowHelper.AskYesOrNo(question);
        }

        public void CloseWindow(VMBase vm)
        {
            windowHelper.CloseWindow(vm);
        }
    }
}

//private readonly IAdminService adminService;

//public Facade(IAdminService adminService)
//{
//    this.adminService = adminService;
//}

//public List<UserData> GetAllUsers()
//{
//    return adminService.GetAllUsers();
//}

//public int CreateUser(string username, bool isActive)
//{
//    throw new NotImplementedException();

//    //return adminService.CreateUser(username, isActive);
//}

//public void UpdateUser(UserData user)
//{
//    adminService.UpdateUser(user);
//}

//public void DeleteUser(int userId)
//{
//    adminService.DeleteUser(userId);
//}

//public void ResetPassword(int userId)
//{
//    throw new NotImplementedException();
//    //adminService.ResetPassword(userId);
//}

//public void ShowError(string message, Exception innerException)
//{
//   
//}

//public bool ConfirmDelete(string itemName)
//{
//    return MessageBox.Show(string.Format("Are you sure want to delete {0}?", itemName), "CLEXA - Admin", MessageBoxButton.YesNo) == MessageBoxResult.Yes;
//}